package com.youkeda.yikao.web.validator;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.http.HttpServletRequest;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * @author ：chenzikang
 * @date ： 2019/9/19
 */

public class EmailCodeValidator implements ConstraintValidator<EmailCode,String> {

    //注入request
    @Autowired
    private HttpServletRequest request;


    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        String emailCode= (String) request.getSession().getAttribute("emailCode");


        return StringUtils.equals(value,emailCode);
    }
}
